package com.scs.application.modules.fsd.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.modules.fsd.dto.SaveRoleDTO;
import com.scs.application.modules.fsd.entity.FsdRole;
import com.scs.application.modules.fsd.service.FsdRoleService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * @Description: 权限管理
 */
@RestController
@RequestMapping("/back_front/roles")
public class FsdRoleController extends CrudController<FsdRoleService, FsdRole> {

    @GetMapping(value = "/getService")
    public RestResult getRoleList(@RequestParam("keyword") String keyword, @RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize") Integer pageSize){
        Map<String, Object> users= service.getRoleList(keyword,currentPage,pageSize);
        return RestResult.ok("get Role list success",users);
    }

    @GetMapping(value = "/getAllService")
    public RestResult findAll(){
       return findAll(false);
    }

    @PostMapping(value = "/createService")
    public RestResult saveRole(@RequestBody @Valid SaveRoleDTO roleDTO) {
        String id = service.saveRole(roleDTO);
        return RestResult.ok("保存成功！",id);
    }

    @PostMapping(value = "/editService")
    public RestResult editRole(@RequestBody @Valid SaveRoleDTO roleDTO) {
        boolean isOk = service.editRole(roleDTO);
        if(isOk)
            return RestResult.ok("保存成功！");
        return RestResult.error("保存失败");
    }
}
